import request from '@/utils/request'
import store from '@/store'

export function codeImgAPI() {
  const clientToken = getNum()
  store.commit('user/CLIENTTOKEN', clientToken)
  return request({
    url: `/api/user-service/user/imageCode/${clientToken}`
  })
}

// 生成32位数字字母随机数
const getNum = () => {
  const chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  let nums = ''
  for (let i = 0; i < 32; i++) {
    const id = parseInt(Math.random() * 61)
    nums += chars[id]
  }
  return nums

  // 获取图片方式二
  // const num = Math.random() * 100
  // export function getcode() {
  //   const url = `/api/user-service/user/imageCode/${num}`
  //   return url
  // }
}
export function loginAPI(data) {
  return request({
    url: '/api/user-service/user/login',
    method: 'POST',
    data
  })
}

